package com.jyc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jyc.entity.zuche.Zuche;
import com.jyc.mapper.zuche.ZucheMapper;
import com.jyc.service.ZucheService;
import com.jyc.util.HttpResult;
import com.jyc.vo.zuche.ZucheChartVO;
import com.jyc.vo.zuche.ZucheInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin("*")
@RequestMapping("/zuche")
public class ZucheController {
    @Autowired
    private ZucheService zucheService;
    @Autowired(required = false)
    private ZucheMapper zucheMapper;

    /**
     * 租车信息
     * @return
     */
    @RequestMapping("/toList")
    public HttpResult toList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<ZucheInfoVO> zucheInfoVOS = zucheService.getItemList();
        PageInfo<ZucheInfoVO> pageInfo = new PageInfo<ZucheInfoVO>(zucheInfoVOS, pageSize);
        Map returnMap = new HashMap();
        returnMap.put("pageInfo",pageInfo);
        returnMap.put("pageTotal",zucheMapper.selectByExample(null).size());
        return HttpResult.ok(returnMap);
    }

    @RequestMapping("/showPie")
    public HttpResult showPie() {
        List<ZucheChartVO> zucheChartVOS = zucheService.showPie();
        return HttpResult.ok(zucheChartVOS);
    }

    @RequestMapping("/showPillar")
    public HttpResult showPillar() {
        List<ZucheChartVO> zucheChartVOS = zucheService.showPillar();
        return HttpResult.ok(zucheChartVOS);
    }

    @RequestMapping("/showLine")
    public HttpResult showLine() {
        List<ZucheChartVO> zucheChartVOS = zucheService.showLine();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * 相同型号车（车名+颜色）价格一致，但是车是不一样的
     * @return
     */
    @RequestMapping("/show3D")
    public HttpResult show3D() {
        List<List> chartVOS = zucheService.show3D();
        return HttpResult.ok(chartVOS);
    }
}
